using _RobotInspection.Interfaces;
using _RobotInspection.Models;
using _RobotInspection.ReApiHelp;
using _RobotInspection.DTO;
using _RobotInspection.Entities;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace _RobotInspection.Repositories
{
    /// <summary>
    /// 仓储类 
    /// </summary>
    public class Repository : IRepository
    {
        private readonly ISqlSugarClient _db;
        private readonly ILogger<Repository> _logger;
        /*
        /// <summary>
        /// 用户相关功能实现
        /// </summary>
        /// <param name="db"></param>
        /// <param name="logger"></param>
        public Repository(ISqlSugarClient db, ILogger<Repository> logger)
        {
            _db = db;
            _logger = logger;
        }

        
        

        /// <summary>
        /// 获取全部用户
        /// </summary>
        /// <returns name="userList">用户集合</returns>
        public async Task<List<users>> GetUsersAsync()
        {
            var userList = await _db.Queryable<users>().ToListAsync();
            return userList;
        }
        /// <summary>
        /// lamda表达式条件查询用户
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public async Task<List<users>> GetUserWithExpressionAsync(Expression<Func<users, bool>> expression)
        {
            var list = await _db.Queryable<users>().Where(expression).ToListAsync();
            return list;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task<users> InsertUserAsync(users user)
        {
            var result = await _db.Insertable(user).ExecuteReturnEntityAsync();
            return result;
        }


        //设备相关
        public async Task<List<equipment>> GetEquipmentsAsync()
        {
            var equipmentList = await _db.Queryable<equipment>().ToListAsync();
            return equipmentList;
        }

        public async Task<List<equipment>> GetEquipmentWithExpressionAsync(Expression<Func<equipment, bool>> expression)
        {
            var equipmentList = await _db.Queryable<equipment>().Where(expression).ToListAsync();
            return equipmentList;
        }
        
        public async Task<ApiResponse<List<DataManagement>>> SelectData(SelectData selectData)
        {
            var query = _db.Queryable<DataManagement>();
            if (!string.IsNullOrEmpty(selectData.SteelNumber))
            {
                query = query.Where(t => t.SteelNumber == selectData.SteelNumber);
            }
            if (selectData.StartTime != null && selectData.EndTime != null)
            {
                query = query.Where(t => t.CreateTime >= selectData.StartTime && t.CreateTime <= selectData.EndTime);
            }
            var data = await query.ToListAsync();

            return ApiResponse<List<DataManagement>>.Success(data);
        }
       */
    }
}